package cn.powerone.scm.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.powerone.common.annotation.Log;
import cn.powerone.common.core.controller.BaseController;
import cn.powerone.common.core.domain.AjaxResult;
import cn.powerone.common.enums.BusinessType;
import cn.powerone.scm.domain.ScmInventoryProductLocation;
import cn.powerone.scm.service.IScmInventoryProductLocationService;
import cn.powerone.common.utils.poi.ExcelUtil;
import cn.powerone.common.core.page.TableDataInfo;

/**
 * 产品与库位对应关系Controller
 *
 * @author PowerOne
 * @date 2025-08-30
 */
@RestController
@RequestMapping("/scm/productlocation")
public class ScmInventoryProductLocationController extends BaseController
{
    @Autowired
    private IScmInventoryProductLocationService scmInventoryProductLocationService;

    /**
     * 查询产品与库位对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('scm:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmInventoryProductLocation scmInventoryProductLocation)
    {
        startPage();
        List<ScmInventoryProductLocation> list = scmInventoryProductLocationService.selectScmInventoryProductLocationList(scmInventoryProductLocation);
        return getDataTable(list);
    }

    /**
     * 导出产品与库位对应关系列表
     */
    @PreAuthorize("@ss.hasPermi('scm:location:export')")
    @Log(title = "产品与库位对应关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmInventoryProductLocation scmInventoryProductLocation)
    {
        List<ScmInventoryProductLocation> list = scmInventoryProductLocationService.selectScmInventoryProductLocationList(scmInventoryProductLocation);
        ExcelUtil<ScmInventoryProductLocation> util = new ExcelUtil<ScmInventoryProductLocation>(ScmInventoryProductLocation.class);
        util.exportExcel(response, list, "产品与库位对应关系数据");
    }

    /**
     * 获取产品与库位对应关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('scm:location:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmInventoryProductLocationService.selectScmInventoryProductLocationById(id));
    }

    /**
     * 新增产品与库位对应关系
     */
    @PreAuthorize("@ss.hasPermi('scm:location:add')")
    @Log(title = "产品与库位对应关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmInventoryProductLocation scmInventoryProductLocation)
    {
        return toAjax(scmInventoryProductLocationService.insertScmInventoryProductLocation(scmInventoryProductLocation));
    }

    /**
     * 修改产品与库位对应关系
     */
    @PreAuthorize("@ss.hasPermi('scm:location:edit')")
    @Log(title = "产品与库位对应关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmInventoryProductLocation scmInventoryProductLocation)
    {
        return toAjax(scmInventoryProductLocationService.updateScmInventoryProductLocation(scmInventoryProductLocation));
    }

    /**
     * 删除产品与库位对应关系
     */
    @PreAuthorize("@ss.hasPermi('scm:location:remove')")
    @Log(title = "产品与库位对应关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmInventoryProductLocationService.deleteScmInventoryProductLocationByIds(ids));
    }
}
